
import {updateLists,postStatusUpdate} from '../../../service/api/api.js'
const state = {
    list: []
}
const mutations = {
    addToList(state, item) {
          state.list.unshift(item)
    },
	setList(state, items) {
	        state.list = items; // 设置整个列表
	    }
} 


const actions = {
	fetchList({ commit }) {
	        return updateLists().then(res => {
				if(res.code === 200 || res.code === '200') {	
					commit('setList', res.rows); // 更新列表
				}else {
					console.log('请求动态列表失败:',res)
				}
	        });
	    },
    addItem({ commit }, item) {
		return postStatusUpdate({
			...item
		}).then(res => {
			if(res.code === 200 || res.code === '200') {
				console.log('新增成功')
			} else {
				console.log('新增动态失败:',res)
			}
		})
        // commit('addToList', item)
    }
}
const getters = {
    getList(state){
        //获取
        return state.list;
    }

}

//暴露出去
export default {
    state,
    mutations,
    actions,
    getters
}